import axios from 'axios'

const state = {
  nickName: ''
}

const mutations = {
  // 更新用户信息
  updateUserInfo(state, nickName) {
    state.nickName = nickName
  }
}

const getters = {
  getName: (state) => {
    return `hello ${state.nickName}`
  }
}

const actions = {
  checkLogin: ({commit, state}) => {
    axios.get('/api/users/checkLogin').then((response) => {
      let res = response.data
      if (res.status === '0') {
        commit('updateUserInfo', res.result.userName)
      }
    })
  },
  actionsTest: ({commit, state}, text) => {
    console.log(text)
  },
  actionsTest1: ({commit, state}, text) => {
    console.log(text)
  },
  actionsTest2: ({commit, state}, text) => {
    console.log(text)
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
